package com.jqr.activity.myrecyclerviewdemo.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.jqr.activity.myrecyclerviewdemo.R;
import com.jqr.activity.myrecyclerviewdemo.model.ItemModel;

import java.util.List;

public abstract class RecycleAdapterBase extends RecyclerView.Adapter<RecycleAdapterBase.InnerHolder> {
    private List<ItemModel> itemModelList;
    public  RecycleAdapterBase(List<ItemModel> itemModelList){
        this.itemModelList=itemModelList;
    }
    @NonNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=getSubView(parent,viewType);
        return  new InnerHolder(view);

    }

    public  abstract View getSubView(@NonNull ViewGroup parent, int viewType);

    @Override
    public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
        holder.setData(itemModelList.get(position));
    }

    @Override
    public int getItemCount() {
        return itemModelList.size();
    }

    public  static  class InnerHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;
        public InnerHolder(@NonNull View itemView) {
            super(itemView);

            imageView=itemView.findViewById(R.id.imageView);

            textView=itemView.findViewById(R.id.textView);

        }
        public void setData(ItemModel itemModel){
            imageView.setImageResource(itemModel.getIcon());
            textView.setText(itemModel.getTitle());

        }

    }
}
